package com.mcxx.modules.supervise.service.write;

import com.mcxx.modules.supervise.dao.write.SuperviseLogWriteDao;
import com.mcxx.modules.supervise.entity.SuperviseLogEntity;
import com.mcxx.modules.system.dto.SuperviseLogDTO;
import com.mcxx.util.Constant;
import com.yinhai.ta404.core.security.vo.UserAccountVo;
import com.yinhai.ta404.core.transaction.annotation.TaTransactional;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.UUID;


@Service
@TaTransactional
public class SuperviseLogWriteService {

    @Autowired
    private SuperviseLogWriteDao superviseLogWriteDao;



    public int insert(SuperviseLogDTO superviseLogDTO, UserAccountVo userAccountVo){
        SuperviseLogEntity superviseLog = new SuperviseLogEntity();
        String id = Constant.getUUID();//UUID.randomUUID().toString().replace("-","");
        superviseLog.setLogid(id);
        superviseLog.setChangecontent(superviseLogDTO.getChangecontent());
        superviseLog.setOptype(superviseLogDTO.getOptype());
        superviseLog.setModulename(superviseLogDTO.getModulename());
        if(null != userAccountVo){
            superviseLog.setOpuserId(userAccountVo.getUserId());
            superviseLog.setOpuser(userAccountVo.getLoginId());
            superviseLog.setOpusername(userAccountVo.getName());
        }
        superviseLog.setOptime(new Date());
        superviseLog.setClientip(superviseLogDTO.getClientip());
        return superviseLogWriteDao.insert(superviseLog);
    }

}
